package com.wzx.service;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.lang.reflect.Executable;
@Component
@Aspect
public class Advice {
    public void writeLog(){
        System.out.println("写一个开发备忘录");
    }
    //try{  }
   // @Before("execution( * com.wzx.service..*.*(..))")
    public void before(){
        System.out.println("before-------");
    }
    //@AfterReturning("execution( * com.wzx.service..*.*(..))")
    public void afterReturn(){
        System.out.println("afterReturn-------");
    }
   //catch(exception e){ }
   // @AfterThrowing("execution( * com.wzx.service..*.*(..))")
    public void afterThrow(){
        System.out.println("afterThrow-------");
    }
    //finally
   // @After("execution( * com.wzx.service..*.*(..))")
    public void after(){
        System.out.println("after-------");
    }

    @Around("execution( * com.wzx.service..*.*(..))")
    public void arround(ProceedingJoinPoint point ){//参目标类中的任意方法
        try{
            //执行before
            before();
            System.out.println("arround-------");
            point.proceed();
            //执行正常返回
            afterReturn();
        }catch (Throwable e){
            //补救方法
            afterThrow();
        }finally {
            //释放资源的方法
            after();
        }
    }
}
